package com.citcc.business.util;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: qinbo
 * Date: 2019/4/6
 * Time: 10:39
 * Description: 集合判断工具类
 */
public abstract class CollectionUtil {

    public static boolean isEmpty(Collection collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isNotEmpty(Collection collection) {
        return collection != null && !collection.isEmpty();
    }

    public static boolean isEmpty(Map map) {
        return map == null || map.isEmpty();
    }

    public static boolean isNotEmpty(Map map) {
        return map != null && !map.isEmpty();
    }

    public static <T> List<T> emptyList() {
        return Collections.EMPTY_LIST;
    }

    public static <K, V> Map.Entry<K, V> getFirst(Map<K, V> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }
        Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
        return iterator.next();
    }

    public static <T> List<T> asList(T... arr) {
        if (arr == null || arr.length == 0) {
            return new ArrayList<>();
        }
        List<T> list = new ArrayList<>(arr.length);
        for (T t : arr) {
            list.add(t);
        }
        return list;
    }

    public static List<Integer> asList(int[] arr) {
        if (arr != null) {
            List<Integer> list = new ArrayList<>();
            for (int i : arr) {
                list.add(i);
            }
            return list;
        }
        return null;
    }

}
